package com.bcu.calculus.utils;

import com.bcu.calculus.entity.CheckAttendance;
import com.bcu.calculus.entity.CheckAttendanceNumber;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CheckAttendanceUtil {

    public static CheckAttendance change(CheckAttendanceNumber checkAttendanceNumber) throws ParseException {
        CheckAttendance checkAttendance = new CheckAttendance();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        if (checkAttendanceNumber.getCheckId() != null) {
            checkAttendance.setCheckId(checkAttendanceNumber.getCheckId());
        }
        if (checkAttendanceNumber.getCheckName() != null) {
            checkAttendance.setCheckName(checkAttendanceNumber.getCheckName());
        }
        if (checkAttendanceNumber.getCheckList() != null) {
            checkAttendance.setCheckList(checkAttendanceNumber.getCheckList());
        }
        if (checkAttendanceNumber.getCheckListId() != null) {
            checkAttendance.setCheckListId(checkAttendanceNumber.getCheckListId());
        }
        if (checkAttendanceNumber.getCheckStatus() != null) {
            checkAttendance.setCheckStatus(checkAttendanceNumber.getCheckStatus());
        }
        if (checkAttendanceNumber.getCheckSemId() != null) {
            checkAttendance.setCheckSemId(checkAttendanceNumber.getCheckSemId());
        }
        if (checkAttendanceNumber.getCheckPosition() != null) {
            checkAttendance.setCheckPosition(checkAttendanceNumber.getCheckPosition());
        }
        if (checkAttendanceNumber.getCheckRemark() != null){
            checkAttendance.setCheckRemark(checkAttendanceNumber.getCheckRemark());
        }

        try {
            if(checkAttendanceNumber.getCheckStartTime() != null){
                Date Time = formatter.parse(checkAttendanceNumber.getCheckStartTime());

                checkAttendance.setCheckStartTime(Time);
            }
        } catch (Exception e) {
            checkAttendance.setCheckStartTime(null);
        }

        try {
            if(checkAttendanceNumber.getCheckStopTime() != null){
                Date Time = formatter.parse(checkAttendanceNumber.getCheckStopTime());

                checkAttendance.setCheckStopTime(Time);
            }
        } catch (Exception e) {
            checkAttendance.setCheckStopTime(null);
        }

        if (checkAttendanceNumber.getCheckQrcode() != null){
            checkAttendance.setCheckQrcode(checkAttendanceNumber.getCheckQrcode());
        }

        if (checkAttendanceNumber.getCheckScore() != null){
            checkAttendance.setCheckScore(checkAttendanceNumber.getCheckScore());
        }

        if (checkAttendanceNumber.getCheckAdminUserId() != null){
            checkAttendance.setCheckAdminUserId(checkAttendanceNumber.getCheckAdminUserId());
        }

        if (checkAttendanceNumber.getCheckAdminUserName() != null){
            checkAttendance.setCheckAdminUserName(checkAttendanceNumber.getCheckAdminUserName());
        }

        try {
            if(checkAttendanceNumber.getCheckCreateTime() != null){
                Date Time = formatter.parse(checkAttendanceNumber.getCheckCreateTime());

                checkAttendance.setCheckCreateTime(Time);
            }
        } catch (Exception e) {
            checkAttendance.setCheckCreateTime(null);
        }

        try {
            if(checkAttendanceNumber.getCheckUpdateTime() != null){
                Date Time = formatter.parse(checkAttendanceNumber.getCheckUpdateTime());

                checkAttendance.setCheckUpdateTime(Time);
            }
        } catch (Exception e) {
            checkAttendance.setCheckUpdateTime(null);
        }

        if (checkAttendanceNumber.getCheckLongitude() != null) {
            checkAttendance.setCheckLongitude(checkAttendanceNumber.getCheckLongitude());
        }
        if (checkAttendanceNumber.getCheckLatitude() != null) {
            checkAttendance.setCheckLatitude(checkAttendanceNumber.getCheckLatitude());
        }
        return checkAttendance;
    }
}
